package com.linian.pushforcampus.mapper;

import com.linian.pushforcampus.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("SELECT * FROM user")
    List<User> getAllUsers();

    @Select("SELECT * FROM user where  user_id = #{user.userId}")
    List<User> getAllUsersByUser(@Param("user") User user);


    @Select("SELECT * FROM user WHERE id = #{id}")
    User getUserById(@Param("id") Integer id);

    @Select("SELECT * FROM user WHERE user_id = #{userid}")
    User getUserByCode(@Param("userid") String code);

    @Select("SELECT * FROM user WHERE datastate =1")
    List<User> getUserByIdWhoState1();

    @Insert("INSERT INTO user (user_id, user_name, datastate, isVip, memo, update_time, create_time) " + "VALUES (#{user.userId}, #{user.userName}, #{user.dataState}, #{user.isVip}, #{user.memo}, #{user.updateTime}, #{user.createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "user.id")
    void insertUser(@Param("user") User user);

    @Update("UPDATE user SET user_id = #{user.userId}, user_name = #{user.userName}, datastate = #{user.dataState}, " + "isVip = #{user.isVip}, memo = #{user.memo}, update_time = #{user.updateTime}, create_time = #{user.createTime} " + "WHERE id = #{user.id}")
    void updateUser(@Param("user") User user);

    @Delete("DELETE FROM user WHERE id = #{id}")
    void deleteUser(@Param("id") Integer id);
}
